package hust.music.util;

import java.util.Calendar;
import java.util.Date;

/**
 * DateConvert
 * 
 * @author Txazo
 * @since 1.0
 */
public class DateConvert {

	/**
	 * 日期转换
	 * 
	 * @param date 日期
	 * @return 日期对应的字符串
	 */
	public static String convertDateToString(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(calendar.get(Calendar.YEAR) + "-");
		stringBuffer
				.append(convertZero(calendar.get(Calendar.MONTH) + 1) + "-");
		stringBuffer.append(convertZero(calendar.get(Calendar.DAY_OF_MONTH))
				+ " ");
		stringBuffer.append(convertZero(calendar.get(Calendar.HOUR_OF_DAY))
				+ ":");
		stringBuffer.append(convertZero(calendar.get(Calendar.MINUTE)) + ":");
		stringBuffer.append(convertZero(calendar.get(Calendar.SECOND)));

		return stringBuffer.toString();
	}

	/**
	 * 数字添零转换
	 * 
	 * @param convert 待转换的数字
	 * @return 转换后的数字
	 */
	public static String convertZero(int convert) {
		if (convert < 10) {
			return "0" + convert;
		}
		return String.valueOf(convert);
	}

}